package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.db.domain.system.SysNotice;
import com.ruoyi.system.service.ISysNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 通知sys_noticeController
 * 
 * @author ruoyi
 * @date 2022-05-10
 */
@Api(value = "通知sys_notice",tags ="通知sys_notice")
@RestController
@RequestMapping("/notice")
public class SysNoticeController extends BaseController
{
    @Autowired
    private ISysNoticeService sysNoticeService;

    /**
     * 查询通知sys_notice列表
     */
    @ApiOperation(value = "查询通知sys_notice列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="sysNotice",value="通知sys_notice",paramType="form")
    })
    @RequiresPermissions("system:notice:list")
    @GetMapping("/list")
    public TableDataInfo list(SysNotice sysNotice)
    {
        startPage();
        List<SysNotice> list = sysNoticeService.selectSysNoticeList(sysNotice);
        return getDataTable(list);
    }

    /**
     * 导出通知sys_notice列表
     */
    @ApiOperation(value = "导出通知sys_notice列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="sysNotice",value="通知sys_notice",dataType="SysNotice")
    })
    @RequiresPermissions("system:notice:export")
    @Log(title = "通知sys_notice", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody SysNotice sysNotice)
    {
        List<SysNotice> list = sysNoticeService.selectSysNoticeList(sysNotice);
        ExcelUtil<SysNotice> util = new ExcelUtil<SysNotice>(SysNotice.class);
        util.exportExcel(response, list, "通知sys_notice数据");
    }

    /**
     * 获取通知sys_notice详细信息
     */
    @ApiOperation(value = "获取通知sys_notice详细信息")
    @ApiImplicitParam(name="noticeId",value="通知sys_notice")
    @RequiresPermissions("system:notice:query")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Long noticeId)
    {
        return AjaxResult.success(sysNoticeService.selectSysNoticeByNoticeId(noticeId));
    }

    /**
     * 新增通知sys_notice
     */
    @ApiOperation(value = "新增通知sys_notice")
    @ApiImplicitParams({
            @ApiImplicitParam(name="sysNotice",value="通知sys_notice",dataType="SysNotice")
    })
    @RequiresPermissions("system:notice:add")
    @Log(title = "通知sys_notice", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysNotice sysNotice)
    {
        return toAjax(sysNoticeService.insertSysNotice(sysNotice));
    }

    /**
     * 修改通知sys_notice
     */
    @ApiOperation(value = "修改通知sys_notice")
    @ApiImplicitParams({
            @ApiImplicitParam(name="sysNotice",value="通知sys_notice",dataType="SysNotice")
    })
    @RequiresPermissions("system:notice:edit")
    @Log(title = "通知sys_notice", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysNotice sysNotice)
    {
        return toAjax(sysNoticeService.updateSysNotice(sysNotice));
    }

    /**
     * 删除通知sys_notice
     */
    @ApiOperation(value = "删除通知sys_notice")
    @ApiImplicitParam(name="noticeIds",value="通知sys_notice")
    @RequiresPermissions("system:notice:remove")
    @Log(title = "通知sys_notice", businessType = BusinessType.DELETE)
	@DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Long[] noticeIds)
    {
        return toAjax(sysNoticeService.deleteSysNoticeByNoticeIds(noticeIds));
    }
}
